<template>
	<view class="result">
		<view class="irr-title">
			<image src="/static/images/common/shuxian.png" mode=""></image>
			收益率
		</view>
		<view class="irr-result">
			<view class="irr">
				<text class="left-label">IRR复利</text>
				<text class="main-text">{{ dl }}%</text>
			</view>
			<view class="si">
				<text class="left-label">SI单利</text>
				<text class="main-text">{{ fl }}%</text>
				<uni-tooltip class="tooltip" content="示例文字" placement="right">
					<image class="tooltip-image" src="/static/images/common/help.png"></image>
				</uni-tooltip>
			</view>
		</view>

		<view class="xjl-title">
			<image src="/static/images/common/shuxian.png" mode=""></image>
			现金流
		</view>
		<view class="xjl-result">
			<view class="line-label">
				第
				<text class="font24">1-{{ jfnx }}</text>
				年，每年缴纳
				<text class="red-text">{{ njbf }}</text>
				元
			</view>
			<view class="line-label">
				第
				<text class="font24">{{ bdnd }}</text>
				年年末，现金价值
				<text class="main-text">{{ xjjz }}</text>
				元
			</view>
			<view class="line-label">
				第
				<text class="font24">{{ qsnd }}</text>
				年至第
				<text class="font24">{{ zznd }}</text>
				年，每年提取
				<text class="main-text">{{ ntqe }}</text>
				元
			</view>
		</view>
	</view>
</template>

<script>
import { FinanceClass } from '../../../../utils/finance.js';
import utils from '../../../../utils/util.js';

export default {
	data() {
		return {
			dl: '', //复利
			fl: '', //单利1 计划书通用模式
			fl2: '', //单利2 数学模型
			jfnx: '**', //缴费年限
			njbf: '**', //年缴保费
			bdnd: '**', //保单年度
			xjjz: '**', //现金价值
			qsnd: '**', //起始年度
			zznd: '**', //终止年度
			ntqe: '**' //年提取额
		};
	},
	onLoad(option) {
		let finance = new FinanceClass();
		let sendData = JSON.parse(option.data);
		this.$data.jfnx = sendData.f_jfnx;
		this.$data.njbf = sendData.f_njbf;
		this.$data.bdnd = sendData.f_bdnd ? sendData.f_bdnd : '**';
		this.$data.xjjz = sendData.f_xjjz ? sendData.f_xjjz : '**';
		this.$data.qsnd = sendData.f_qsnd ? sendData.f_qsnd : '**';
		this.$data.zznd = sendData.f_zznd ? sendData.f_zznd : '**';
		this.$data.ntqe = sendData.f_ntqe ? sendData.f_ntqe : '**';

		for (var t = [], u = 0; u < sendData.f_jfnx; u++) t[u] = -sendData.f_njbf;
		if (sendData.f_qsnd !== '' && sendData.f_zznd !== '') {
			for (var l = sendData.f_qsnd, m = sendData.f_zznd, c = sendData.f_ntqe, f = l - 1; f < m; f++) t[f] || (t[f] = 0), (t[f] += Number(c));
		}
		sendData.f_bdnd && sendData.f_xjjz && (t[sendData.f_bdnd] = sendData.f_xjjz);
		for (var p = 0; p < t.length; p++) t[p] || (t[p] = 0);
		var dl = finance.IRR2(t);
		var fl = (100 * utils.calculateWeightInterestIRR(t)).toFixed(2);
		var fl2 = (100 * utils.calculateSimpleInterestIRR(t)).toFixed(2);
		this.$data.dl = dl;
		this.$data.fl = fl;
		this.$data.fl2 = fl2;
	},
	methods: {}
};
</script>

<style lang="stylus">
.result
	margin-bottom: 20px
	margin-top: 20rpx
	.irr-title
		font-weight: bold
		margin-top: 50rpx
		font-size: 38rpx
		image
			height: 45rpx
			width: 45rpx
			vertical-align: middle
	.irr-result
		margin-left: 80rpx
		line-height: 60rpx
		.irr
			display: flex
			align-items: center
			font-weight: bold
			.left-label
				align-items: center
				border-bottom: 1px solid #444444
				padding: 4px
				min-width: 80px
			.main-text
				color: #e81e25
				font-size: 24px
				min-width: 80px
				border-bottom: 1px solid #444444
				padding: 4px
		.si
			display: flex
			align-items: center
			font-weight: bold
			.left-label
				border-bottom: 1px solid #444444
				padding: 4px
				min-width: 80px
			.main-text
				color: #e81e25
				font-size: 24px
				border-bottom: 1px solid #444444
				min-width: 80px
				padding: 4px
			.tooltip
				.tooltip-image
					height: 40rpx
					width: 40rpx
	.xjl-title
		font-weight: bold
		margin-top: 50rpx
		font-size: 38rpx
		image
			height: 45rpx
			width: 45rpx
			vertical-align: middle
	.xjl-result
		margin-left: 80rpx
		line-height: 60rpx
		font-weight: bold
		.line-label
			margin-top: 20rpx
			.red-text
				color: #e81e25
				font-size: 24px
				padding: 0 4px
			.font24
				color: #e81e25
				font-size: 24px
				padding: 0 4px
			.main-text
				color: #e81e25
				font-size: 24px
				padding: 0 4px
</style>
